package lemna.top.chunyu.batch.step2;

import java.util.List;

import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;

import lemna.top.chunyu.batch.Constant.IsOK;
import lemna.top.chunyu.batch.step1.domain.ChunYuPaymentStatement;
import lemna.top.chunyu.batch.step1.repo.ChunYuRepo;
import lemna.top.chunyu.batch.step2.domain.AlipayPaymentStatement;
import lemna.top.chunyu.batch.step2.repo.AlipayRepo;
import lemna.top.chunyu.batch.step3.domain.WeiXiPaymentStatement;
 


public class Step2Writer implements ItemWriter<AlipayPaymentStatement> {
	@Autowired
	AlipayRepo repo;

	@Autowired
	ChunYuRepo chunYuRepo;

	@Override
	public void write(List<? extends AlipayPaymentStatement> items) throws Exception {
		for (AlipayPaymentStatement t : items) {
//			repo.save(t);
          saveItem(t);
			
		}

	}
    private void saveItem(AlipayPaymentStatement item )
    {

        ChunYuPaymentStatement order = chunYuRepo.findByChunYuOrderNo(item.getMerchantOrderNo());
        Long totalMoney = new Double(item.getOrderAmount()*100).longValue();
        if(order.getOrderAmount()==totalMoney)
        {
            order.setIsOK(IsOK.YES);
            chunYuRepo.save(order);
        }
    }
}